<?php

$filename="user.txt";
$file=fopen($filename,"r");


$user = $_GET['userName'];
$pass = $_GET['password'];

$flag=false;

while(!feof($file))
{

    //在将JSON数据解码的时候,加入第二参数true,使其返回的数据为数组
    $json = json_decode(fgets($file),true);
    if($json["userName"] == $user){
        if($json["password"] == $pass){
            $flag = true;
            echo "账号密码正确";
            break;
        }else{
            $flag = true;
            echo "密码错误";
            break;
        }
    }else{
        $flag = false;
    }
}
if ($flag == false){
    echo "不存在该用户";
}

//关闭
fclose($file);